<template>
	<div class="on-premise-form">
		<el-table :data="tableData" style="width: 100%"  min-height="300" size="small">
			<el-table-column type="index" label="点位" width="80" />
			<el-table-column prop="ptzPresetName" label="名称" />
			<el-table-column label="操作" fixed="right" width="150">
				<template #default="scope">
					<el-button type="primary" text @click="invokeHandle(scope.row)">调用</el-button>
					<el-button type="primary" text @click="setHandle(scope.row)">设置</el-button>
					<el-button type="danger" text @click="deleteHandle(scope.row)">删除</el-button>
				</template>
			</el-table-column>
		</el-table>
	</div>
</template>

<script setup lang="ts">
import { ref, onMounted } from 'vue'
import { ElMessage } from 'element-plus/es'
import { useTurnPresetListApi, useTurnPresetPositionApi, useTurnPresetSetApi, useTurnPresetDelApi } from '../../../api/contols'

const props = defineProps({
	liveOptions: {
		type: Object,
		default: () => ({}),
		required: true
	}
})
const tableData = ref<any[]>([])
const getTableData = async () => {
	if (props.liveOptions.serial) {
		const { data } = await useTurnPresetListApi({ ...props.liveOptions })
		tableData.value = data
	} else {
		tableData.value = []
	}
}

// 调用
const invokeHandle = async (row: any) => {
	await useTurnPresetPositionApi({
		...props.liveOptions,
		preset: row.ptzPresetNo // 预置位id
	})

	ElMessage.success({
		message: '调用成功',
		duration: 1000,
		onClose: () => {}
	})
}

// 设置
const setHandle = async (row: any) => {
	await useTurnPresetSetApi({
		...props.liveOptions,
		preset: row.ptzPresetNo, // 预置位id
		name: row.name // 预置位名称
	})

	ElMessage.success({
		message: '设置成功',
		duration: 1000,
		onClose: () => {}
	})
}

// 删除
const deleteHandle = async (row: any) => {
	await useTurnPresetDelApi({
		...props.liveOptions,
		preset: row.ptzPresetNo // 预置位id
	})

	ElMessage.success({
		message: '删除成功',
		duration: 1000,
		onClose: () => {}
	})
}

onMounted(() => {
	getTableData()
})

defineExpose({})
</script>

<style lang="scss" scoped></style>
